package com.wly.login.common;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author wly
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

	// 捕获 ValidationException
	@ExceptionHandler(ValidationException.class)
	@ResponseStatus(HttpStatus.BAD_REQUEST)
	public Result<String> handleValidationException(ValidationException e) {
		return new Result<>(400, e.getMessage(), null);
	}

	// 捕获其他异常
	@ExceptionHandler(Exception.class)
	@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
	public Result<String> handleException(Exception e) {
		return new Result<>(500, "服务器内部错误", null);
	}
}
